package com.iam.core.exceptions;

import cn.dev33.satoken.exception.NotLoginException;
import com.iam.core.entities.Result;
import com.iam.core.enums.ResultEnum;
import com.iam.core.utils.ResultUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author camel
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 全局异常拦截
     * @param e 未登录异常
     * @return
     */
    @ExceptionHandler
    public Result handlerException(NotLoginException e, HttpServletResponse response) {
        response.setStatus(HttpStatus.UNAUTHORIZED.value());
        return ResultUtil.error(ResultEnum.UNAUTHORIZED.getCode(), e.getMessage());
    }

}
